<?php

require_once("Common/MobileDetect.php");

class SkinView {

	private $skinChoice = "Skin";
	private $cookieExpires;
	private $detect;

	public function __construct() {
		$this -> cookieExpires = time() + 60 * 3;
		$this->detect = new MobileDetect();
	}
	
	/**
	 * function to get skinchoice from user
	 * @access public
	 * @param -
	 * @return int option
	 */
	public function getSkin() {

		if (isset($_GET[$this -> skinChoice])) {
			return $_GET[$this -> skinChoice];
		}
		
		elseif (isset($_COOKIE[$this -> skinChoice])) {
			return $_COOKIE[$this -> skinChoice];
		}
		
		else if ($this->detect -> isMobile()) {
			return SkinHandler::ALT_SKIN;
		}
		
		else {
			return null;
		}
	}
	
	/**
	 * Function to set skinoption to cookie
	 * @access public
	 * @param int option
	 * @return -
	 */
	public function setSkinToCookie($a_opt) {
		setcookie($this -> skinChoice, $a_opt, $this -> cookieExpires);
	}
	
	/**
	 * Function to generate skin option links, if mobile visitor
	 * @access public
	 * @param -
	 * @return HTML
	 */
	public function generateSkinOptionLinks() {
		if($this->detect -> isMobile()){
			return "<div class='skinLinksDiv'>
					<a href='?$this->skinChoice=1'>Webbview</a>
					<a href='?$this->skinChoice=2'>Mobileview</a>
				</div>";
		}
		return "";
	}

}
